﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="md5.min.js"></script>

    <script type="text/javascript">
        function test() {
            let str = "qweQWE123"; //1FA3356B1EB65F144A367FF8560CB406
            //str = '{"name":"嘻嘻嘻嘻嘻嘻嘻嘻嘻","age":22}';//56b21847ed32d2d96cf74077b22342eb
            let md5Value = md5(str).toUpperCase();
            console.log(md5Value);
        }

        /**
         * 全屏是否可用
         * */
        function fullscreenEnabled() {
            return (
                document.fullscreenElement ||
                document.mozFullScreenElement ||
                document.webkitFullscreenElement
            );
        }



        /**
         * 全屏
         * @param ele 全屏显示的元素
         */
        function primitiveFullscreen(element) {
            if (document.mozFullScreenEnabled) {
                return Promise.reject(new Error("全屏模式被禁用"));
            }
            let result = null;
            if (element.requestFullscreen) {
                result = element.requestFullscreen();
            }
            else if (element.mozRequestFullScreen) {
                result = element.mozRequestFullScreen();
            }
            else if (element.msRequestFullscreen) {
                result = element.msRequestFullscreen();
            }
            else if (element.webkitRequestFullscreen) {
                result = element.webkitRequestFullScreen();
            }
            return result || Promise.reject(new Error("不支持全屏"));
        }



        /**
       * 获取当前全屏的节点
       * */
        function getFullscreenElement() {
            return (
                document.fullscreenElement ||
                document.mozFullScreenElement ||
                document.msFullScreenElement ||
                document.webkitFullscreenElement || null
            );
        }

        function fullscreen() {
            let ele = document.body;
            //let ele = document.getElementById("div");
            if (ele) {
                primitiveFullscreen(ele);
            }
            else {
                console.warn("无法全屏");
            }
        }

        /**
         * 退出全屏
         * */
        function exitFullscreen() {
            //if (document.exitFullScreen) {
            //    document.exitFullScreen();
            //} else if (document.mozCancelFullScreen) {
            //    document.mozCancelFullScreen();
            //} else if (document.webkitExitFullscreen) {
            //    document.webkitExitFullscreen();
            //} else if (document.msExitFullscreen) {
            //    document.msExitFullscreen();
            //}

            if (document.exitFullscreen) {
                document.exitFullscreen();
            } else if (document.msExitFullscreen) {
                document.msExitFullscreen();
            } else if (document.mozCancelFullScreen) {
                document.mozCancelFullScreen();
            } else if (document.webkitExitFullscreen) {
                document.webkitExitFullscreen();
            }
        }



        /**
         * 判断当前是否全屏
         * */
        function isFullScreen() {
            return !!(
                document.fullscreen ||
                document.mozFullScreen ||
                document.webkitIsFullScreen ||
                document.webkitFullScreen ||
                document.msFullScreen
            );
        }

        /**
         *判断当前文档是否能切换到全屏
         * */
        function isFullscreenEnabled() {
            return (
                document.fullscreenEnabled ||
                document.mozFullScreenEnabled ||
                document.webkitFullscreenEnabled ||
                document.msFullscreenEnabled
            );
        }
    </script>
</head>
<body>
    <div id="div">
        <button onclick="test()">test</button>
        <button onclick="fullscreen()">fullscreen</button>
        <button onclick="exitFullscreen()">exitFullscreen</button>
    </div>
</body>
</html>